﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}

<script src="~/lib/layui/layui.js"></script>
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />

<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>



<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.20/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">工序编码</label>
            <div class="layui-input-inline">
                <input type="text" placeholder="请输入" class="layui-input" style="width:200px" id="procedureCode" />
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-form" onclick="Automatic()">
                <input type="checkbox" name="CCC" title="自动生成|关闭自动生成" lay-skin="switch" class="GMon" value="1">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">工序名称</label>
            <div class="layui-input-inline">
                <input type="text" placeholder="请输入" class="layui-input" style="width:200px" id="processName" />
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">是否启用</label>
            <div class="layui-input-inline">
                <div class="layui-form" onclick="Automatics()">
                    <input type="checkbox" name="CCC" title="是|否" lay-skin="switch" onclick="" class="GMonss" value="1">
                </div>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">工序说明</label>
            <div class="layui-input-inline">
                <textarea name="" placeholder="多行文本框" class="layui-textarea" style="width:500px" id="processInstructions"></textarea>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline">
                <textarea name="" placeholder="多行文本框" class="layui-textarea" style="width:500px" id="descriptionToreMark"></textarea>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <div class="layui-input-inline">
                <button type="button" class="layui-btn layui-btn-primary layui-btn-radius" onclick="Stach()">修改</button>
                <button type="button" class="layui-btn layui-btn-primary layui-btn-radius" lay-on="test-iframe-curl">新增</button>
            </div>
        </div>
    </div>
    <div>
        <table class="layui-hide" id="ID-table-demo-data"></table>
    </div>
    <script type="text/html" id="toolDemo">
        <div class="layui-clear-space">
          <a onclick="Update()" lay-on="test-iframe-curr"  style="color:cornflowerblue">修改</a>
        </div>
    </script>
</body>
</html>
<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->


<script src="//unpkg.com/layui@2.9.20/dist/layui.js"></script>


<script>


    $(() => {

        ProcessBack()
        HtmlView()
    })

    var getisEnable = "";
    //工序反填
    function ProcessBack() {
        var processid = location.href.split("=")[1];
        $.ajax({

            url: '@ViewBag.FoundationRead' + "/api/Acquire/processBack",
            type: "post",
            data: JSON.stringify({ Processid: processid }),
            dataType: "json",
            contentType: "application/json",
            success: res => {
                $("#procedureCode").val(res.data[0].procedureCode);
                $("#processName").val(res.data[0].processName);
                if (res.data[0].isEnable == 0) {
                    $(".GMonss").prop("checked", true);
                    getisEnable = 0;
                }
                else
                {
                    getisEnable = 1;
                }
                $("#processInstructions").val(res.data[0].processInstructions);
                $("#descriptionToreMark").val(res.data[0].descriptionToreMark);
            }
        })





    }



    //自动生成
    function Automatic() {


        var gh = $('.GMon:checked').val()
        console.log(gh);

        if (gh == 1) {
            var Encoding = "MG" + Math.random().toString().substring(2, 6);

            $("#procedureCode").val(Encoding)
        }
        if (gh != 1) {
            $("#procedureCode").val('');
        }
    }


   ///工序步骤

    function Automatics() {


        var gh = $('.GMonss:checked').val()
        console.log(gh);

        if (gh == 1) {
            getisEnable = 0;
        }
        if (gh != 1) {
            getisEnable = 1;
        }
    }

  
    //工序修改
    function Stach() {

        var gh = location.href.split("=")[1];

        var date = {

            processid: gh,
            procedureCode: $("#procedureCode").val(),
            processName: $("#processName").val(),
            isEnable: getisEnable,
            processInstructions: $("#processInstructions").val(),
            descriptionToreMark: $("#descriptionToreMark").val(),
        };
        console.log(date, '222')
        $.ajax({
            url: '@ViewBag.FoundationWrite' + "/api/Jocker/processUpdate",
            type: 'post',
            data: JSON.stringify(date),
            dataType: "json",
            contentType: "application/json",
            success: res => {
                if (res.code > 0) {
                    alert("修改成功");
                }
            }
        })
    }

    ///工序对应步骤

    function HtmlView() {


        var processid = location.href.split("=")[1];

        $.ajax({

            url: '@ViewBag.FoundationRead'+ '/api/Acquire/StepDescriptionHtml',
            data: JSON.stringify({ stepid: processid }),
            type: "post",
            async: false,
            dataType: "json",
            contentType: "application/json",
            success: res => {

                console.log(res.data, '555');
                layui.use('table', function () {
                    var table = layui.table;

                    // 已知数据渲染
                    var inst = table.render({
                        elem: '#ID-table-demo-data',
                        cols: [[ //标题栏
                            { type: 'checkbox', title: '复选框', fixed: true }, // 单选框
                            { field: 'orderid', title: '顺序编号', width: 200, sort: true },
                            { field: 'materialURl', title: '步骤说明', width: 200 },
                            { field: 'auxiliaryEquipment', title: '辅助设备', width: 200 },
                            { field: 'materialF', title: '辅助材料', width: 200 },
                            { field: 'stepDescription', title: '备注', width: 200 },
                            { fixed: 'right', title: '操作', width: 134, minWidth: 125, templet: '#toolDemo' }
                        ]],
                        data: res.data,
                        //skin: 'line', // 表格风格
                        //even: true,
                        page: true, // 是否显示分页
                        limits: [5, 10, 15],
                        limit: 5 // 每页默认显示的数量
                    })
                })
            }
        })
    }



    var $ = layui.$;
    var table = layui.table
    var getid = "";
    // 触发表格复选框选择
    table.on('checkbox(ID-table-demo-data)', function (obj) {
        getid = obj.data.processtepid
        console.log(getid,'ttt');
        // 事件
      
    })




    var processid = location.href.split("=")[1];
    var $ = layui.$;
    var layer = layui.layer;
    var util = layui.util;

    util.on('lay-on', {
        'test-iframe-curl': function () {
            layer.open({
                type: 2,
                title: '增加步骤',
                shadeClose: true,
                maxmin: true, //开启最大化最小化按钮
                area: ['900px', '600px'],
                content: '/Document/Description?id=' + processid
            });
        }
    })
    //修改
    util.on('lay-on', {

        'test-iframe-curr': function () {
           

            layer.open({
                type: 2,
                title: '修改步骤',
                shadeClose: true,
                maxmin: true, //开启最大化最小化按钮
                area: ['900px', '600px'],
                content: '/Document/DEesCsiptionBacnk?id=' + getid
            });
        }
    })

</script>

@* 
    var gh = location.href.split("=")[1];
        console.log(); *@